<script setup lang="ts">
import { ref } from "vue";
import { useHost } from "./hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddForm from "./addForm.vue";
import TrimForm from "./trimForm.vue";

import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import More from "@iconify-icons/ep/more-filled";

const formRef = ref();

const clickTrimBut = row => {
  dialogFormTrimRef.value.showTrimDialog(row);
};
const {
  dialogFormAddRef,
  dialogFormTrimRef,
  loading,
  form,
  columns,
  dataList,
  buttonClass,
  onSearch,
  resetForm,
  handleSelectionChange,
  handleUpdateHostAppsClick
} = useHost();
</script>

<template>
  <div>
    <TrimForm ref="dialogFormTrimRef" @onSearchEnv="onSearch" />
    <AddForm ref="dialogFormAddRef" @onSearchEnv="onSearch" />
    <div class="main">
      <div class="float-right w-[99%]">
        <el-form
          ref="formRef"
          :inline="true"
          :model="form"
          class="bg-bg_color w-[99/100] pl-8 pt-4"
        >
          <el-form-item label="主机名称">
            <el-input
              v-model="form.name"
              placeholder="请输入hostname"
              clearable
              class="!w-[160px]"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              :icon="useRenderIcon(Search)"
              :loading="loading"
              @click="onSearch"
            >
              搜索
            </el-button>
            <el-button
              :icon="useRenderIcon(Refresh)"
              @click="resetForm(formRef)"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
        <PureTableBar title="主机管理" @refresh="onSearch">
          <template v-slot="{ size, checkList }">
            <pure-table
              border
              align-whole="center"
              table-layout="auto"
              :loading="loading"
              :size="size"
              :data="dataList"
              :columns="columns"
              :checkList="checkList"
              :header-cell-style="{
                background: 'var(--el-table-row-hover-bg-color)',
                color: 'var(--el-text-color-primary)'
              }"
              @selection-change="handleSelectionChange"
            >
              <template #operation="{ row }">
                <el-button
                  class="reset-margin"
                  link
                  type="primary"
                  :size="size"
                  :icon="useRenderIcon(More)"
                  @click="clickTrimBut(row)"
                >
                  维护
                </el-button>
                <el-dropdown>
                  <el-button
                    class="ml-3 mt-[2px]"
                    link
                    type="primary"
                    :size="size"
                    :icon="useRenderIcon(More)"
                  />
                  <template #dropdown>
                    <el-dropdown-menu>
                      <el-dropdown-item>
                        <el-button
                          @click="handleUpdateHostAppsClick(row)"
                          :class="buttonClass"
                          link
                          type="primary"
                          :size="size"
                          :icon="useRenderIcon(More)"
                        >
                          扫描应用
                        </el-button>
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-button
                          disabled
                          :class="buttonClass"
                          link
                          type="primary"
                          :size="size"
                          :icon="useRenderIcon(More)"
                        >
                          重启服务器
                        </el-button>
                      </el-dropdown-item>
                    </el-dropdown-menu>
                  </template>
                </el-dropdown>
              </template>
            </pure-table>
          </template>
        </PureTableBar>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>

function defineOptions(arg0: { name: string; }) { throw new Error("Function not
implemented."); }
